package com.wilmer.options.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.options.domain.YwOptions;
import com.wilmer.options.service.IYwOptionsService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 题库题选项Controller
 *
 * @author zl
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/options/options")
public class YwOptionsController extends BaseController {
    @Autowired
    private IYwOptionsService ywOptionsService;

    @PreAuthorize("@ss.hasPermi('options:options:list')")
    @GetMapping({"/list"})
    public TableDataInfo list(YwOptions ywOptions) {
        this.startPage();
        List<YwOptions> list = this.ywOptionsService.selectYwOptionsList(ywOptions);
        return this.getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('options:options:export')")
    @Log(
            title = "题库题选项",
            businessType = BusinessType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, YwOptions ywOptions) {
        List<YwOptions> list = this.ywOptionsService.selectYwOptionsList(ywOptions);
        ExcelUtil<YwOptions> util = new ExcelUtil(YwOptions.class);
        util.exportExcel(response, list, "题库题选项数据");
    }

    @PreAuthorize("@ss.hasPermi('options:options:query')")
    @GetMapping({"/{optionId}"})
    public AjaxResult getInfo(@PathVariable("optionId") Long optionId) {
        return this.success(this.ywOptionsService.selectYwOptionsByOptionId(optionId));
    }

    @PreAuthorize("@ss.hasPermi('options:options:add')")
    @Log(
            title = "题库题选项",
            businessType = BusinessType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody YwOptions ywOptions) {
        return this.toAjax(this.ywOptionsService.insertYwOptions(ywOptions));
    }

    @PreAuthorize("@ss.hasPermi('options:options:edit')")
    @Log(
            title = "题库题选项",
            businessType = BusinessType.UPDATE
    )
    @PutMapping
    public AjaxResult edit(@RequestBody YwOptions ywOptions) {
        return this.toAjax(this.ywOptionsService.updateYwOptions(ywOptions));
    }

    @PreAuthorize("@ss.hasPermi('options:options:remove')")
    @Log(
            title = "题库题选项",
            businessType = BusinessType.DELETE
    )
    @DeleteMapping({"/{optionIds}"})
    public AjaxResult remove(@PathVariable Long[] optionIds) {
        return this.toAjax(this.ywOptionsService.deleteYwOptionsByOptionIds(optionIds));
    }
}